package com.hamster.crmpre.web;

import com.hamster.crmpre.config.LoginInterceptor;
import com.hamster.crmpre.pojo.EmployeePerformance;
import com.hamster.crmpre.pojo.ExecutivePerformance;
import com.hamster.crmpre.service.CompanyAccountService;
import com.hamster.crmpre.service.EmployeePerformanceService;
import com.hamster.crmpre.service.ExecutivePerformanceService;
import com.hamster.crmpre.service.PersonalMoneyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @author ：Lizhipeng
 * @date ：Created in 2019/12/28 15:49
 * @description：明细控制器
 * @modified By：
 * @version: 1.0
 */
@RestController
@RequestMapping("detailed")
public class DetailedController {
    
    @Autowired
    private EmployeePerformanceService employeePerformanceService;
    @Autowired
    private ExecutivePerformanceService executivePerformanceService;
    @Autowired
    private PersonalMoneyService personalMoneyService;
    @Autowired
    private CompanyAccountService companyAccountService;
    /**
     * 获取具体时间的个人业绩
     * @param time
     * @return
     */
    @GetMapping("person")
    public Map<String,Object> detailed(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date time){
        Map<String, Object> map = new HashMap<>();
        String userId = LoginInterceptor.getLoginUser().getUserId();
        List<EmployeePerformance> employeePerformanceList = employeePerformanceService.getByTime(userId, time);
        List<ExecutivePerformance> executivePerformanceList = executivePerformanceService.getByTime(userId, time);
        map.put("员工业绩",employeePerformanceList);
        map.put("主管业绩",executivePerformanceList);
        return map;
    }

    /**
     * 查询个人收支明细 流水账
     * @param time 当前月份
     * @return  当月总额   当月流水记录 降序
     */
    @GetMapping("personalDetails")
    public  Map<String,Object> personalDetails(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date time){

        String userId = LoginInterceptor.getLoginUser().getUserId();
        Calendar cal = Calendar.getInstance();
        cal.setTime(time);
        cal.add(Calendar.MONTH,1);
        Date nextMonthTime = cal.getTime();
        Map<String, Object> map = personalMoneyService.personalDetails(userId,time,nextMonthTime);

        return map;
    }

    /**
     *  事业部 查询分公司收支明细 流水账
     * @param time 当前月份
     * @return  当月总额   当月流水记录 降序
     */
    @GetMapping("companyPersonalDetail")
    public  Map<String,Object> companyPersonalDetail(@RequestParam String companyId,@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date time){

        String userId = companyId;
        Calendar cal = Calendar.getInstance();
        cal.setTime(time);
        cal.add(Calendar.MONTH,1);
        Date nextMonthTime = cal.getTime();
        Map<String, Object> map = personalMoneyService.personalDetails(userId,time,nextMonthTime);

        return map;
    }


    /**
     * 查询公司收支明细 流水账
     * @param time 当前月份
     * @return  当月总额   当月流水记录 降序
     */
    @GetMapping("companyDetails")
    public  Map<String,Object> companyDetails(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date time){
        Calendar cal = Calendar.getInstance();
        cal.setTime(time);
        cal.add(Calendar.MONTH,1);
        Date nextMonthTime = cal.getTime();
        Map<String, Object> map = companyAccountService.companyDetails(time,nextMonthTime);
        return map;
    }



}
